package com.itic.appbase.framework.utils.configuration;

/**
 * properties文件操作工具类.
 * 
 * @author: zhaokechun
 * @date: 2015年5月5日 下午2:37:39
 * @version: V1.0
 */
public class PropertyHelper {

    private static final Configuration cfg = ConfigurationFactory.getConfiguration();

    private PropertyHelper() {
    }

    public static String getString(String key) {
        return cfg.getString(key);
    }

    public static boolean getBoolean(String key) {
        return cfg.getBoolean(key);
    }

    public static String getString(String key, String defaultVal) {
        String cfgValue = cfg.getString(key);
        return (cfgValue == null || cfgValue.trim().length() == 0) ? defaultVal : cfgValue;
    }

    public static String[] getStringArray(String key) {
        return cfg.getStringArray(key);
    }

    public static int getInt(String key) {
        return cfg.getInt(key);
    }

    public static long getLong(String key) {
        return cfg.getLong(key);
    }

    public static int getInt(String key, int defaultVal) {
        int value = cfg.getInt(key);
        return value == -1 ? defaultVal : value;
    }

    public static double getDouble(String key, double defaultVal) {
        double value = cfg.getDouble(key);
        return (Double.doubleToRawLongBits(value) == 0) || (Double.isNaN(value)) ? defaultVal : value;
    }
}
